package com.b1502.store2.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.KeyEvent;
import android.webkit.WebView;
import android.widget.TextView;

import com.b1502.store2.R;
import com.b1502.store2.model.bean.NewsDetailBean;
import com.b1502.store2.network.StoreParams;
import com.b1502.store2.util.UrlUtil;
import com.google.gson.Gson;

import org.xutils.common.Callback;
import org.xutils.x;

import java.util.ArrayList;
import java.util.List;

/**
 * 资讯详情页面
 */
public class NewsDetailActivity extends BaseActivity {

    private String userid;
    private TextView tv_name_newsdetail;
    private TextView tv_time_newsdetail;
    private RecyclerView rv_message_newsdetail;
    private RecyclerView rv_message_newsdetail1;

    List<NewsDetailBean> list=new ArrayList<>();
    private WebView webView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Intent intent = getIntent();

        userid = intent.getStringExtra("userid");

        webView = new WebView(this);

        //设置WebView属性，能够执行Javascript脚本
        webView.getSettings().setJavaScriptEnabled(true);
        //加载需要显示的网页
        webView.loadUrl("http://web.alinq.cn/store2/#home_news?id=648cf203-16f0-4603-b291-40864c472356");
        //设置Web视图
        setContentView(webView);

//        setContentView(R.layout.activity_news_detail);
//
//        initView();
//
//        Intent intent = getIntent();
//
//        userid = intent.getStringExtra("userid");
//
//        Log.d("uuuu",userid);

//        initStoreBar("资讯详情");
//
//        setStoreBarTitle("资讯详情");
//
//        getNews("newsId",userid);
    }

    @Override
    //设置回退
    //覆盖Activity类的onKeyDown(int keyCoder,KeyEvent event)方法
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()) {
            webView.goBack(); //goBack()表示返回WebView的上一页面
            return true;
        }
        return false;

    }

    private void initView() {

        tv_name_newsdetail = (TextView) findViewById(R.id.tv_name_newsdetail);

        tv_time_newsdetail = (TextView) findViewById(R.id.tv_time_newsdetail);

        rv_message_newsdetail1 = (RecyclerView) findViewById(R.id.rv_message_newsdetail);

    }

    private void getNews(String param, String newsId) {
        StoreParams params = new StoreParams(UrlUtil.GetNews,param,newsId);

        Log.d("sos",params+"");

        x.http().get(params, new Callback.CommonCallback<String>() {
            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onSuccess(String result) {

                Gson gson=new Gson();

                NewsDetailBean newsDetailBean = gson.fromJson(result, NewsDetailBean.class);

                Log.d("ooo",newsDetailBean.getId());

                tv_name_newsdetail.setText(newsDetailBean.getTitle());

                tv_time_newsdetail.setText(newsDetailBean.getCreateDateTime());

            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {

            }

            @Override
            public void onFinished() {

            }
        });
    }
}
